﻿@{
    Script.Require("jQueryUI_Droppable");
    Script.Require("Gravity");
    Style.Require("Gravity_Debug");
 
    var tag = Tag(Model, "div");
        
    IHtmlString zoneRender = null;
}
@tag.StartElement
    @using(var c=Capture(captured=>{ zoneRender=captured; })) {
        @Display(Model.Metadata.ChildContent)
    }
	@{
        // Check for drop partial render
        // TODO: Simplify and move off into a method if possible
        if ((Model.DropZoneId!=null) && this.Context.Items.Contains(Downplay.Gravity.Filters.AjaxFilterProvider.AjaxFilterHttpContextKey))
        {
            var dropContext = Context.Items[Downplay.Gravity.Filters.AjaxFilterProvider.AjaxFilterHttpContextKey] as Downplay.Gravity.Filters.AjaxFilterContext;
            if (dropContext != null && dropContext.IsPartialRender)
            {
                if (dropContext.Result.Updates.ContainsKey((string)(Model.DropZoneId)))
                {
                    dropContext.Response.Updates.Add(new Downplay.Gravity.Filters.PartialUpdateReplaceDefinition()
                    {
                        Behaviour = Downplay.Gravity.Filters.PartialUpdateBehaviours.Replace,
                        HtmlContent = zoneRender.ToString(),
                        ReplaceZoneId = Model.DropZoneId,
                        UpdateZoneId = Model.DropZoneId
                    });
                    
                }
            }
        }
	}
@tag.EndElement